//
//  untitled.m
//  SCRAP_ObjC
//
//  Created by Capstone Design Fall 2010 on 10/22/10.
//  Copyright 2010 Thunderwear. All rights reserved.
//

#import "StackAdditions.h"


@implementation NSMutableArray (StackAdditions)

- (id)pop
{
	// nil if [self count] == 0
    id lastObject = [self lastObject];
    if (lastObject)
        [self removeLastObject];
    return lastObject;
}

- (id)top {
	return [self lastObject];
}

- (BOOL)isEmpty {
	return [self count]==0;
}

- (void)push:(id)obj
{
	[self addObject: obj];
}

- (NSMutableArray *) popFrom:(id)obj
{
	int index = [self indexOfObject:obj];
	NSMutableArray * array = [[NSMutableArray alloc] initWithCapacity:5];
	
	// push items into new array
	for (int i=index; i<[self count]; i++) {
		[array push:[self objectAtIndex:i]];
	}
	
	[self removeObjectsInRange:NSMakeRange(index, [self count]-index)];
	
	return array;
}

@end
